package com.java.dormitorymanager.impl;

import com.java.dormitorymanager.dao.IStudentDao;
import com.java.dormitorymanager.pojo.Manager;
import com.java.dormitorymanager.pojo.Student;
import com.java.dormitorymanager.util.BasicDao;

import java.util.List;

/**
 * @program: DormitoryManager
 * @description: IStudentDao的实现类
 * @author: ShuangChenYue
 * @create: 2021-05-16 18:20
 **/
public class StudentDaoImpl implements IStudentDao
{

    @Override
    public void studentRegister(Student student)
    {
        BasicDao.updateData("insert into student(name,password,stunum,age,gender,email,status) value(?,?,?,?,?,?,?)",student.getName(),student.getPassword(),student.getStunum(),student.getAge(),student.getGender(),student.getEmail(),student.getStatus());
    }

    @Override
    public List<Student> findAllMaleStudents()
    {
        return BasicDao.getObjectToList(Student.class,"select * from student where gender='male'");
    }

    @Override
    public List<Student> findAllFemaleStudents()
    {
        return BasicDao.getObjectToList(Student.class,"select * from student where gender='female'");
    }

    @Override
    public Student findStudentByName(String name)
    {
        return BasicDao.getObject(Student.class,"select * from student where name=?",name);
    }

    @Override
    public Student findStudentById(int id)
    {
        return BasicDao.getObject(Student.class,"select * from student where id=?",id);
    }

    @Override
    public void deleteStudentById(int id)
    {
        BasicDao.updateData("delete from student where id=?",id);
    }

    @Override
    public void updateStudent(Student student)
    {
        BasicDao.updateData("update student set name=?,password=?,stunum=?,age=?,gender=?,email=?,status=?,dornum=? where id=?",student.getName(),student.getPassword(),student.getStunum(),student.getAge(),student.getGender(),student.getEmail(),student.getStatus(),student.getDornum(),student.getId());
    }

    @Override
    public List<Student> findAllMaleStudentsWithoutDorm()
    {
        return BasicDao.getObjectToList(Student.class,"select * from student where dornum='null' and gender='male'");
    }

    @Override
    public List<Student> findAllFemaleStudentsWithoutDorm()
    {
        return BasicDao.getObjectToList(Student.class,"select * from student where dornum='null' and gender='female'");
    }

}
